# This file is intended to be a final submission. python tester.py Player.py
# should work at all times. If it does not, there is a bug.
# If you're just trying to test a solution, scroll down to the Player
# class.

# This file is intended to be in the same format as a valid solution, so
# that users can edit their solution into Player and then submit just this
# file to the contest. If you see any reason this would not work, please submit
# an Issue to https://github.com/ChadAMiller/hungergames/issues or email me.

# You can see more sample player classes in bots.py

class BasePlayer(object):
    '''
    Base class so I don't have to repeat bookkeeping stuff.
    Do not edit unless you're working on the simulation.
    '''
    
    def __str__(self):
        try:
            return self.name
        except AttributeError:
            # Fall back on Python default
            return super(BasePlayer, self).__repr__()
    
    def hunt_choices(*args, **kwargs):
        raise NotImplementedError("You must define a strategy!")
        
    def hunt_outcomes(*args, **kwargs):
        pass
        
    def round_end(*args, **kwargs):
        pass


class Player(BasePlayer):
    '''
    Your strategy starts here.
    '''

    def __init__(self):
        self.name = 'DakshOld'
        self.count_hunts = 0
        self.count_hunters = 0
        self.extra_foods = 0
        self.choices = []
        self.partner_old_reputation = 0
        self.min_rep = 0
        
    def hunt_choices(
                    self,
                    round_number,
                    current_food,
                    current_reputation,
                    m,
                    player_reputations,
                    ):
        '''Required function defined in the rules'''
        # Find hunters of current round
        self.count_hunters = 0
        self.choices = []
        for n in range(len(player_reputations)):
            if player_reputations[n] > 0:
                self.count_hunters += 1
        
        # Sit for first round
        if round_number == 1:
            return ['s'] * len(player_reputations)

        # If we dont have, or he is gonna lose, change the partner
        elif self.partner_old_reputation <= 0.05:
            # Find the partner with minimum reputation and please NO sitter
            self.min_rep = 1.000
            for i in range(len(player_reputations)):
                if player_reputations[i] < self.min_rep and player_reputations[i] > 0.001:
                    self.min_rep = player_reputations[i]
            # If we find our partner, set his reputation
            if self.min_rep != 1.000:
                self.partner_old_reputation = self.min_rep
  
            self.choices.append('h') # Hunt once

            for j in range(len(player_reputations)-1): # Sit againt other player
                self.choices.append('s')

            return self.choices 

        
        # Co-ordinate with partner
        else:
            # find the sitters and avg reputation
            s = 0
            for cnt_s in range(len(player_reputations)):
                if player_reputations[cnt_s] < 0.001:
                    s += 1

            
            # If all are sitters
            if cnt_s == len(player_reputations):
                return ['s'] * len(player_reputations)

            # Co operate
            else:
                for i in range(len(player_reputations)):
                    # If he is my partner or he is pro hunter, and he chose to hunt - hunt with
                    if current_reputation == player_reputations[i] and player_reputations[i] != self.partner_old_reputation:
                        self.choices.append('h')
                        self.partner_old_reputation = player_reputations[i]
                    else:
                        self.choices.append('s')
                return self.choices


        

    def hunt_outcomes(self, food_earnings):
        '''Required function defined in the rules'''
        pass
        

    def round_end(self, award, m, number_hunters):
        '''Required function defined in the rules'''
        # Update the total nummber of hunts
        self.count_hunts += number_hunters
        # Store extra foods I got from the awards
        self.extra_foods += award 
        pass
        